package com.cobra.consumer;

import com.cobra.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;

@EnableAutoConfiguration
public class TimeoutDubboConsumerDemo {

    @Reference(version = "timeout", timeout = 3000)
    private DemoService demoService;
    public static void main(String[] args) throws IOException {
        ConfigurableApplicationContext context = SpringApplication.run(TimeoutDubboConsumerDemo.class);

        DemoService demoService = context.getBean(DemoService.class);

        //服务端设置将服务睡眠5s，那么再客户端将会直接报错
        //org.apache.dubbo.remoting.TimeoutException
        //但是服务端代码只会打印一行warn日志
        //DubboServerHandler-169.254.104.84:20881-thread-2  WARN filter.TimeoutFilter
        System.out.println((demoService.sayHello("cobra"))); //xxservestub
    }
}
